home *** CD-ROM | disk | FTP | other *** search
- property pMySprite, pHSLField, pFieldLimit
- global gCast, gSize, gFirstColor, gSecondColor, gWvBgColor, gWvBgShadow, gWvVcolor, gWvVShadow, gWvHcolor, gWvHShadow, gHSL, gCurrentHSL, gTargetHSLColor, gHue, gSat, gLight, gRed, gGreen, gBlue
-
- on beginSprite me
- pMySprite = sprite(me.spriteNum)
- end
-
- on mouseEnter me
- if gHSL <> VOID then
- put "Click and drag to adjust the " & pHSLField.word[1] & "." into field "status"
- end if
- end
-
- on mouseDown me
- sliderHSL(me)
- end
-
- on mouseLeave me
- if gHSL <> VOID then
- put EMPTY into field "status"
- end if
- end
-
- on resetHSLSlider
- put 0 into field "Hue status"
- put 0 into field "Saturation status"
- put 0 into field "Lightness status"
- sprite(189).locH = sprite(279).left
- sprite(190).locH = sprite(279).left
- sprite(191).locH = sprite(279).left
- end
-
- on sliderHSL newloch
- if gHSL <> VOID then
- gCurrentHSL = duplicate(gHSL)
- repeat while the mouseDown
- newloch = the mouseH
- if newloch < (sprite(278).left - 1) then
- newloch = sprite(278).left - 1
- end if
- if newloch > sprite(279).right then
- newloch = sprite(279).right
- end if
- pMySprite.locH = newloch
- put integer((newloch - sprite(279).left) / 100.0 * pFieldLimit) into field pHSLField
- updateStage()
- end repeat
- cursor(4)
- updateHSL()
- cursor(0)
- gCurrentHSL = VOID
- else
- beep()
- pass()
- end if
- end
-
- on updateHSL
- repeat with Y = 0 to integer(gSize) - 1
- repeat with X = 0 to integer(gSize) - 1
- gTargetHSLColor = gHSL.getPixel(X, Y)
- calculateHSL()
- gHue = gHue + integer(the text of field "Hue status")
- if gHue < 0 then
- gHue = gHue + 360
- else
- if gHue >= 360 then
- gHue = gHue - 360
- end if
- end if
- if integer(the text of field "Saturation status") >= 0 then
- satStep = (100 - gSat) / 100.0
- gSat = integer(gSat + (integer(the text of field "Saturation status") * satStep))
- else
- satStep = (0 - gSat) / 100.0
- gSat = integer(gSat - (integer(the text of field "Saturation status") * satStep))
- end if
- if integer(the text of field "Lightness status") >= 0 then
- lightStep = (100 - gLight) / 100.0
- gLight = integer(gLight + (integer(the text of field "Lightness status") * lightStep))
- else
- lightStep = (0 - gLight) / 100.0
- gLight = integer(gLight - (integer(the text of field "Lightness status") * lightStep))
- end if
- calculateRGB()
- gCurrentHSL.setPixel(X, Y, rgb(gRed, gGreen, gBlue))
- end repeat
- end repeat
- member("adj hsl - " & gSize, gCast).image.copyPixels(gCurrentHSL, member("adj hsl - " & gSize, gCast).rect, gCurrentHSL.rect)
- updateStage()
- end
-
- on calculateHSL
- pRed = gTargetHSLColor.red / 255.0
- pGreen = gTargetHSLColor.green / 255.0
- pBlue = gTargetHSLColor.blue / 255.0
- pMin = min(pRed, pGreen, pBlue)
- pMax = max(pRed, pGreen, pBlue)
- pDelta = pMax - pMin
- gLight = (pMax + pMin) / 2
- if pMax = pMin then
- gSat = 0
- gHue = 0
- else
- if gLight <= 0.5 then
- gSat = pDelta / (pMax + pMin)
- else
- gSat = pDelta / (2 - pMax - pMin)
- end if
- if pRed = pMax then
- gHue = (pGreen - pBlue) / pDelta
- else
- if pGreen = pMax then
- gHue = 2 + ((pBlue - pRed) / pDelta)
- else
- if pBlue = pMax then
- gHue = 4 + ((pRed - pGreen) / pDelta)
- end if
- end if
- end if
- end if
- gHue = integer(gHue * 359 / 6)
- if gHue < 0 then
- gHue = gHue + 360
- else
- if gHue >= 360 then
- gHue = gHue - 360
- end if
- end if
- gSat = integer(gSat * 100)
- gLight = integer(gLight * 100)
- end
-
- on calculateRGB
- pHue = gHue / 360.0
- pSat = gSat / 100.0
- pLight = gLight / 100.0
- if pSat = 0 then
- gRed = integer(pLight * 255)
- gGreen = integer(pLight * 255)
- gBlue = integer(pLight * 255)
- else
- if pLight <= 0.5 then
- temp2 = pLight * (1 + pSat)
- else
- temp2 = pLight + pSat - (pLight * pSat)
- end if
- temp1 = (2 * pLight) - temp2
- tempRed = pHue + 0.33329999999999999
- if tempRed < 0 then
- tempRed = tempRed + 1.0
- end if
- if tempRed > 1 then
- tempRed = tempRed - 1.0
- end if
- if (6 * tempRed) < 1 then
- tempRed = temp1 + ((temp2 - temp1) * 6 * tempRed)
- else
- if (2 * tempRed) < 1 then
- tempRed = temp2
- else
- if (3 * tempRed) < 2 then
- tempRed = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempRed) * 6)
- else
- tempRed = temp1
- end if
- end if
- end if
- tempGreen = pHue
- if tempGreen < 0 then
- tempGreen = tempGreen + 1.0
- end if
- if tempGreen > 1 then
- tempGreen = tempGreen - 1.0
- end if
- if (6 * tempGreen) < 1 then
- tempGreen = temp1 + ((temp2 - temp1) * 6 * tempGreen)
- else
- if (2 * tempGreen) < 1 then
- tempGreen = temp2
- else
- if (3 * tempGreen) < 2 then
- tempGreen = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempGreen) * 6)
- else
- tempGreen = temp1
- end if
- end if
- end if
- tempBlue = pHue - 0.33329999999999999
- if tempBlue < 0 then
- tempBlue = tempBlue + 1.0
- end if
- if tempBlue > 1 then
- tempBlue = tempBlue - 1.0
- end if
- if (6 * tempBlue) < 1 then
- tempBlue = temp1 + ((temp2 - temp1) * 6 * tempBlue)
- else
- if (2 * tempBlue) < 1 then
- tempBlue = temp2
- else
- if (3 * tempBlue) < 2 then
- tempBlue = temp1 + ((temp2 - temp1) * (0.66659999999999997 - tempBlue) * 6)
- else
- tempBlue = temp1
- end if
- end if
- end if
- gRed = integer(tempRed * 255)
- gGreen = integer(tempGreen * 255)
- gBlue = integer(tempBlue * 255)
- end if
- end
-
- on getPropertyDescriptionList me
- list = [:]
- addProp(list, #pHSLField, [#comment: "Field Member Name.", #format: #string, #default: "Hue status"])
- addProp(list, #pFieldLimit, [#comment: "Total field range.", #format: #integer, #default: 200])
- return list
- end
-